﻿
namespace Service
{
    using Data.Repository;
	using System.Collections.Generic;

    public class ProductPictureService : IProductPictureService
    {
        private IProductPictureRepository _productPictureRepository;

        #region IProductPictureService Members

        /// <summary>
        /// create new ProductPicture
        /// </summary>
        /// <param name="theNewProductPicture">the new ProductPicture instance</param>
        /// <returns>the new ProductPicture's ID</returns>
        public int CreateNewProductPicture(Data.Entity.ProductPicture theNewProductPicture)
        {
            if (theNewProductPicture == null)
            {
                return 0;
            }

            if (_productPictureRepository == null)
            {
                _productPictureRepository = new ProductPictureRepository();
            }

            return _productPictureRepository.CreateNewProductPicture(theNewProductPicture);
        }

		public int DeleteProductPicture(Data.Entity.ProductPicture theProductPicture)
        {
			if(theProductPicture == null || theProductPicture.ProductID <= 0 || theProductPicture.PictureID <= 0)
			{
                return 0;
            }

            if (_productPictureRepository == null)
            {
                _productPictureRepository = new ProductPictureRepository();
            }

            return _productPictureRepository.DeleteProductPicture(theProductPicture);
        }

		public IList<Data.Entity.ProductPicture> GetProductPictureByProduct(int productID)
		{
			if(productID <= 0)
			{
				return null;
			}

			if(_productPictureRepository == null)
			{
				_productPictureRepository = new ProductPictureRepository();
			}

			return _productPictureRepository.GetProductPictureByProduct(productID);
		}

		public int UpdateProductPicture(Data.Entity.ProductPicture theProductPicture)
		{
			if(theProductPicture == null || theProductPicture.ProductPictureID <= 0)
			{
				return 0;
			}

			if(_productPictureRepository == null)
			{
				_productPictureRepository = new ProductPictureRepository();
			}

			return _productPictureRepository.UpdateProductPicture(theProductPicture);
		}

		#endregion
	}
}
